package com.yunxin.zm.service.impl;

import com.yunxin.basis.servlet.impl.BasisServiceImpl;
import com.yunxin.zm.domain.ChapterTableEntity;
import com.yunxin.zm.domain.dto.BookChapterJoinDTO;
import com.yunxin.zm.domain.dto.ChapterContentTableDTO;
import com.yunxin.zm.domain.dto.ChapterTableDTO;
import com.yunxin.zm.domain.query.ChapterTableQuery;
import com.yunxin.zm.domain.save.ChapterTableSave;
import com.yunxin.zm.mapper.ChapterTableMapper;
import com.yunxin.zm.service.IBookChapterJoinService;
import com.yunxin.zm.service.IChapterContentTableService;
import com.yunxin.zm.service.IChapterTableService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *Service业务层处理
 * 
 * @author hjl
 * @date Mon Mar 03 09:14:13 CST 2025
 */
@Service
public class ChapterTableServiceImpl extends BasisServiceImpl<ChapterTableEntity, ChapterTableMapper, ChapterTableDTO, ChapterTableSave, ChapterTableQuery> implements IChapterTableService {

   public ChapterTableServiceImpl(ChapterTableMapper mapper) {super(mapper);}

   @Resource
   private IBookChapterJoinService bookChapterJoinService;

   @Resource
   private IChapterContentTableService contentTableService;

   @Override
   public List<ChapterTableDTO> chapterList(Long bid) {
      List<BookChapterJoinDTO> chapter = bookChapterJoinService.findBookChapter(bid);
      if (chapter.isEmpty())return List.of();
      List<Long> idList = chapter.stream().map(BookChapterJoinDTO::getCId).toList();
      List<ChapterTableEntity> tableEntities = baseMapper.selectList(createQuery().in(ChapterTableEntity::getId, idList));
      return genericConverter.toDTOList(tableEntities);
   }

   @Override
   public ChapterContentTableDTO chapterDetail(Long cid) {
      return contentTableService.findById(cid);
   }
}
